<?php
/**
 * Note:
 * Date: 2021/12/29
 */
namespace App\Models\Game\Center;

use App\Traits\ModelTrait;

class AppWebpage extends Base
{
    use ModelTrait;

    public const TYPE_WEB_PC = 'web_pc';
    public const TYPE_WEB_H5 = 'web_h5';
    public const TYPE_AGREEMENT = 'agreement';
    public const TYPE_PRIVACY = 'privacy';
    public const TYPE_CUSTOMER = 'customer';

    protected $table = 'app_webpage';

    public $timestamps = false;

    public $fillable = [
        'type',
        'name',
        'path',
        'is_default',
        'sources',
    ];

    protected $casts = [
        'sources' => 'json',
        'is_default' => 'bool',
    ];

    protected $appends = [
        'full_path',
    ];

    /**
     * @return string
     */
    public function getFullPathAttribute(): string
    {
        if (strpos($this->path, '//') !== false) return $this->path;

        return getCdnSiteUrl($this->path);
    }
}
